//
//  PayViewController.m
//  ApeExample
//
//  Created by Eton on 2017/8/4.
//  Copyright © 2017年 王-庭协. All rights reserved.
//

#import "PayViewController.h"
#import "PayParam.h"

@interface PayViewController ()

@property (weak, nonatomic) IBOutlet UIView *payView;

@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *selectPayTypeButtons;
@property (weak, nonatomic) IBOutlet UIButton *balanceTypeButton;
@property (weak, nonatomic) IBOutlet UIButton *wechatTypeButton;
@property (weak, nonatomic) IBOutlet UIButton *alipayTypeButton;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *balanceViewHeightLayout;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *wechatViewHeightLayout;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *alipayViewHeightLayout;
@property (weak, nonatomic) IBOutlet UILabel *balanceLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;

@property (nonatomic, assign) PayPlatformType payPlatformType;

@end

@implementation PayViewController

- (void)awakeFromNib{
    [super awakeFromNib];
    //    self.payAction = PayPlatformAction_All;
    self.payAction = PayPlatformAction_Balance | PayPlatformAction_Alipay | PayPlatformAction_Wechat;
    
//    self.balanceLabel.text = FORMAT(@"¥%@",[NSString tx_valueOfFloatZero:[kGlobalData selectInstitution].balance]);
//    [kNotification addObserver:self selector:@selector(updateBalanceData) name:K_DID_GET_ACCOUNT_INFO_NOTIFICATION object:nil];
}

- (void)updateBalanceData{
//    self.balanceLabel.text = FORMAT(@"¥%@",[NSString tx_valueOfFloatZero:[kGlobalData selectInstitution].balance]);
}

- (void)setPayPrice:(double)payPrice{
    _payPrice = payPrice;
    self.priceLabel.text = FORMAT(@"¥%.2f",payPrice);
}

- (void)setPayAction:(PayPlatformAction)payAction{
    _payAction = payAction;
    
    if (payAction & PayPlatformAction_Alipay) {
        self.alipayViewHeightLayout.constant = 55;
        [self selectPayTypeAction:self.alipayTypeButton];
    }else{
        self.alipayViewHeightLayout.constant = 0;
    }
    
    if (payAction & PayPlatformAction_Wechat) {
        self.wechatViewHeightLayout.constant = 55;
        [self selectPayTypeAction:self.wechatTypeButton];
    }else{
        self.wechatViewHeightLayout.constant = 0;
    }
    
    if (payAction & PayPlatformAction_Balance) {
        self.balanceViewHeightLayout.constant = 55;
        [self selectPayTypeAction:self.balanceTypeButton];
    }else{
        self.balanceViewHeightLayout.constant = 0;
    }
//    self.payViewHeightLayout.constant = 207 + self.balanceViewHeightLayout.constant + self.wechatViewHeightLayout.constant+ self.alipayViewHeightLayout.constant;
}

- (IBAction)selectPayTypeAction:(UIButton *)sender {
    for (UIButton * button in self.selectPayTypeButtons) {
        button.selected = NO;
    }
    sender.selected = YES;
    if (sender == self.balanceTypeButton) {
        self.payPlatformType = PayPlatformType_Balance;
    }else if (sender == self.wechatTypeButton) {
        self.payPlatformType = PayPlatformType_Wechat;
    }else if (sender == self.alipayTypeButton){
        self.payPlatformType = PayPlatformType_Alipay;
    }
}

- (IBAction)closeAction:(id)sender {
    if (self.closeBlock) {
        self.closeBlock(self.payPlatformType);
    }
}
- (IBAction)confrimPayAction:(id)sender {
    
    if (self.confirmPayBlock) {
        self.confirmPayBlock(self.payPlatformType,self.payPrice);
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
